package com.carworld.controller;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.carworld.config.BaseController;
import com.carworld.model.ShopOrder;
import com.carworld.model.SysOffice;
import com.carworld.utils.DateUtils;

public class StatisticController  extends BaseController{

	/**
	 *  查询一周店铺收入数据
	 */
	public void getStatisticData(){
		System.out.println("查询一周店铺收入数据");
		SysOffice shop=SysOffice.dao.findShopInCache(getUserCookie());
		Object object=null;
		if(shop!=null){
			System.out.println("shop----》"+shop.toString());
			object=ShopOrder.dao.getStatisticPage(shop.getId());
		//	object=ShopOrder.dao.getStatisticPage("d4e86a6d4eb1483989618b186e944785");
		}else{
			object=ShopOrder.dao.getStatisticPage("");
		}
		renderPageJson(object);
	}

	/**
	 * 根据日期查询收入
	 */
	public void getPageOfIncome(){
		
		SysOffice shop=SysOffice.dao.findShopInCache(getUserCookie());
		Object object=null;
		String beginTime=getPara("beginTime");
		String endTime=getPara("endTime");
		if(shop!=null){
			System.out.println("shop----》"+shop.toString());
			object=ShopOrder.dao.getPageOfIncome(shop.getId(),beginTime,endTime);
		}else{
			object=ShopOrder.dao.getPageOfIncome("",beginTime,endTime);
		}
		renderPageJson(object);
	}
	
	/**
	 * 根据年月日查询收入
	 */
	public void getSumIncomeByTime(){
	  
		SysOffice shop=SysOffice.dao.findShopInCache(getUserCookie());
		Object yearIncome=null;
		Object monthIncome=null;
		Object dayIncome=null;
		
		String year=DateUtils.getCurrentYear(new Date());
		String month=DateUtils.getCurrentMonth(new Date());
		String day=DateUtils.getCurrentDate(new Date());
		
		if(shop!=null){
			System.out.println("shop----》"+shop.toString());
			yearIncome=ShopOrder.dao.getSumIncomeByTime(shop.getId(),year).getList();
			monthIncome=ShopOrder.dao.getSumIncomeByTime(shop.getId(),month).getList();
			dayIncome=ShopOrder.dao.getSumIncomeByTime(shop.getId(),day).getList();
		};
		JSONObject jsonObject = getJsonObject();
		jsonObject.put("yearIncome", yearIncome);
		jsonObject.put("monthIncome", monthIncome);
		jsonObject.put("dayIncome", dayIncome);
		renderJson(jsonObject);
	}
	
	
	
	
}
